package com.byit.Test.Mytest1.TestWait;

/**
 * @ClassName ThreadWait
 * @Description TODO
 * @Author lxp
 * @Date 2018/10/8 0008
 **/
public class MyThreadWait extends Thread {

    private String name;
    private Object prev;
    private Object selfl;

    public MyThreadWait(String name, Object prev, Object selfl) {
        this.name = name;
        this.prev = prev;
        this.selfl = selfl;
    }

    @Override
    public void run() {

        int count = 10;
        while (count > 0) {
            synchronized (prev) {
                synchronized (selfl) {

                    System.out.println(name);
                    count--;
                    selfl.notify();
                }
                try {
                    prev.wait();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
